<?php
/**
 * Created by PhpStorm.
 * User: qixiuxiu
 * Date: 2017/4/7
 * Time: 14:41
 */
namespace Simplex;

//引用事件订阅器
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

//class GoogleListener implements EventSubscriberInterface
class GoogleListener
{
    public function onResponse(ResponseEvent $event){
        $response = $event->getResponse();
        //仅在响应“没有被重定向”、请求的格式（format）是HTML并且响应的content-type也是HTML的时候,添加了Google统计代码
        if ($response->isRedirection()
            || ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html'))
            || 'html' !== $event->getRequest()->getRequestFormat()){
            return;
        }
         $response->setContent($response->getContent().'GA CODE 监听1');
        $response->send();
    }

//    //GoogleListener事件监听继承订阅器EventSubscriberInterface接口（知晓所有它感兴趣的事件），通过getSubscribedEvents（）方法将此信息传给地上dispacher
//    public static function getSubscribedEvents()
//    {
//        // TODO: Implement getSubscribedEvents() method.
//        return array('response'=>'onResponse');
//    }
}